Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remark-toc

Package Overview
Dependencies
Maintainers
14
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-toc

Generate a Table of Contents (TOC) for Markdown files

  • 5.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
14
Created
Source

remark-toc

Build Coverage Downloads Chat Sponsors Backers

Generate a Table of Contents in remark.

Installation

npm:

npm install remark-toc

Usage

Say we have the following file, example.md:

# Alpha

## Table of Contents

## Bravo

### Charlie

## Delta

And our script, example.js, looks as follows:

var vfile = require('to-vfile')
var remark = require('remark')
var toc = require('remark-toc')

remark()
  .use(toc)
  .process(vfile.readSync('example.md'), function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Now, running node example yields:

# Alpha

## Table of Contents

-   [Bravo](#bravo)

    -   [Charlie](#charlie)

-   [Delta](#delta)

## Bravo

### Charlie

## Delta

API

remark().use(toc[, options])

Add a Table of Contents to a Markdown document.

  • Looks for the first heading containing 'Table of Contents', 'toc', or 'table-of-contents' (case insensitive, supports alt/title attributes for links and images too)
  • Removes all following contents until an equal or higher heading is found
  • Inserts a list representation of the hierarchy of following headings
  • Adds links to following headings, using the same slugs as GitHub
Options
heading

string?, default: 'toc|table[ -]of[ -]contents?' — Heading to look for, wrapped in new RegExp('^(' + value + ')$', 'i').

maxDepth

number?, default: 6 — Maximum heading depth to include in the table of contents, This is inclusive, thus, when set to 3, level three headings, are included (those with three hashes, ###).

tight

boolean?, default: false — Whether to compile list-items tightly.

Contribute

See contributing.md in remarkjs/remark for ways to get started.

This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 22 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc